// 单线程触发CPU密集型的操作的劣势: 后面的代码被密集型的CPU计算阻塞了(sleepTimer)

const http = require('http')

// 模拟 Sleep
function sleepTimer(time) {
  const sleep = Date.now() + time * 1000
  while (Date.now() < sleep) {}
  return
}

console.info('ready to sleep')
sleepTimer(4)
console.info('sleep finished, wake up')

const server = http.createServer((req, res) => {
  // 浏览器充当客户端,在我们当前服务端发送一个请求
  res.end('server starting..........')
})

server.listen(8080, () => {
  console.info('server is running on 8080')
})
